package com.quartz.springbootquartz.simple;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class JobDemo2 {


    public static void main(String[] args) throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("myJob", "myGroup")
                .usingJobData("name", "zhxl")
                .build();

        JobDetail jobDetail2 = JobBuilder.newJob(MyJob2.class)
                .withIdentity("myJob2", "myGroup")
                .usingJobData("name", "zhxl")
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()
                // 触发器标识
                .withIdentity("trigger1", "trigger1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(2).repeatForever())
                .startNow()
                .build();

        Trigger trigger2 = TriggerBuilder.newTrigger()
                // 触发器标识
                .withIdentity("trigger2", "trigger1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(2).repeatForever())
                .startNow()
                .build();

        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.scheduleJob(jobDetail2, trigger2);
        scheduler.start();


    }
}